package com.demo.dao;

import com.demo.entity.Major;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface MajorMapper {
    @Delete({
        "delete from major",
        "where cmajor_id = #{cmajorId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String cmajorId);

    @Insert({
        "insert into major (cmajor_id, cname, ",
        "college, cmax)",
        "values (#{cmajorId,jdbcType=VARCHAR}, #{cname,jdbcType=VARCHAR}, ",
        "#{college,jdbcType=VARCHAR}, #{cmax,jdbcType=INTEGER})"
    })
    int insert(Major record);

    int insertSelective(Major record);

    @Select({
        "select",
        "cmajor_id, cname, college, cmax",
        "from major",
        "where cmajor_id = #{cmajorId,jdbcType=VARCHAR}"
    })
    @ResultMap("BaseResultMap")
    Major selectByPrimaryKey(String cmajorId);

    int updateByPrimaryKeySelective(Major record);

    @Update({
        "update major",
        "set cname = #{cname,jdbcType=VARCHAR},",
          "college = #{college,jdbcType=VARCHAR},",
          "cmax = #{cmax,jdbcType=INTEGER}",
        "where cmajor_id = #{cmajorId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Major record);

    @Select({
          "select * from major"
    })
    @ResultMap("BaseResultMap")
    List<Major> selectAll();

    @Select({
            "select * from major group by college"
    })
    @ResultMap("BaseResultMap")
    List<Major> selectCollege();
}